package com.chixing.day18_thread;

public class PublicResource {
    private int number =0;
    //生产面包

    public  synchronized void  produce(){
        if (number ==20){
            try {
                wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }else {
            number++;
            System.out.println("生产生产了一个面包，number="+number);
            this.notify();
        }
    }
    //消费面包
    public synchronized void consume(){
        if (number ==0){
            try {
                wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }else {
            number--;
            System.out.println("消费者消费类一个面包， number="+number);
            this.notify();
        }
    }
}
